import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";
import ShoppingView from "../views/ShoppingView.vue";
import ShoppingCart from "../views/ShoppingCart.vue";
import MyView from "../views/MyView.vue";
import SearchView from "../views/SearchView.vue";
Vue.use(VueRouter);

const routes = [
    {
        path: "/",
        name: "home",
        component: HomeView,
        children: [
            // 购物
            {
                path: "shopping",
                name: "shopping",
                alias: "/",
                component: ShoppingView,
            },
            //购物车
            {
                path: "shoppingcart",
                name: "shoppingcart",
                component: ShoppingCart,
                children: [
                    {
                        path: "pay",
                        name: "pay",
                        component: () => import("../views/PayView.vue"),
                    },
                ],
            },
            // 个人主页
            {
                path: "my",
                name: "my",
                component: MyView,
            },
        ],
    },
    // 搜索
    {
        path: "/search",
        name: "search",
        component: SearchView,
    },
    // 商品详细页
    {
        path: "/productdetails/:id",
        name: "productdetails",
        component: () => import("../views/ProductDetails.vue"),
    },
    // 注册
    {
        path: "/signup",
        name: "signup",
        component: () => import("../views/SignUp.vue"),
    },
    // 登录
    {
        path: "/login",
        name: "login",
        component: () => import("../views/LoginView.vue"),
    },
    //历史纪律
    {
        path: "/history",
        name: "history",
        component: () => import("../views/HistoryView.vue"),
    },
];

const router = new VueRouter({
    mode: "history",
    base: process.env.BASE_URL,
    routes,
});

export default router;
